package pers.jzh.std.scala.chapter6

import scala.util.Try

object ChapterApp extends App {

  val rationalA = new Rational(1, 2)
  val rationalB = new Rational(3, 2)
  val rationalC = new Rational(5)
  val rationalD = new Rational(0, 4)
  val result1 = rationalA + rationalB + rationalC + rationalD
  println(result1)

  val tmpA: Rational = null
  Try(println(rationalA + tmpA))
//  val tmpB: Rational = new Rational(null, 4)

  // scala中的 + 和 *是有优先级的
  val result2 = rationalA + rationalB * rationalC
  println(result2)

  println(rationalC * 6 + rationalA * 2)

  val rational = new Rational(3, 4)
  println(rational - new Rational(1, 4))
  println(rational - new Rational(2, 4))

  println(rational / 2)
  println(rational / new Rational(5, 6))


}
